package com.nebula.api.job;

import com.nebula.api.modules.message.entity.SystemMessage;
import com.nebula.api.modules.message.service.ISysMessageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Dengyangbo
 * @date 2020/9/26 22:31
 * @email 13005100647@163.com
 * @description OrderJob
 */
@Component
public class OrderJob {


    @Autowired
    private ISysMessageService sysMessageService;

    private static final List<String> TO_USERS = Arrays.asList("张三", "王兀", "张柳", "李逵", "李四", "赵六", "李清", "伍媚", "李白", "张柳", "四一", "吴起", "赵文贤", "任小龙", "东方不败");
    private static final List<String> PUBLISH_USERS = Arrays.asList("张三", "王兀", "张柳", "李逵", "李四", "赵六", "李清", "伍媚", "李白", "张柳", "四一", "吴起", "赵文贤", "任小龙", "东方不败");


    /**
     * 自动处理消息
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    public void autoCreateMsg() {
        Integer count = sysMessageService.lambdaQuery().eq(SystemMessage::getIsReader, 1).count();
        if (count <= 10) {
            List<SystemMessage> msgList = new ArrayList<>();

            for (String publishUser : PUBLISH_USERS) {
                for (String toUser : TO_USERS) {
                    if (!StringUtils.equals(publishUser, toUser)) {
                        SystemMessage msg = new SystemMessage();
                        msg.setSourceName(publishUser);
                        msg.setSendName(toUser);
                        msg.setCreateTime(LocalDateTime.now());
                        msg.setTitle("系统消息");
                        msg.setType(1);
                        msg.setMsgDate("祝您中秋团圆,国庆快乐! TO:" + toUser + "I am: " + publishUser);
                        msgList.add(msg);
                    }
                }
            }
            for (String publishUser : PUBLISH_USERS) {
                for (String toUser : TO_USERS) {
                    if (!StringUtils.equals(publishUser, toUser)) {
                        SystemMessage msg = new SystemMessage();
                        msg.setSourceName(publishUser);
                        msg.setSendName(toUser);
                        msg.setCreateTime(LocalDateTime.now());
                        msg.setTitle("个人消息");
                        msg.setType(2);
                        msg.setMsgDate("现在是在做企业项目,一切的辛苦付出,都是为了以后更好的就业,可以走的更远,以后可以过的更好,为了美好的明天,好好加油!!!");
                        msgList.add(msg);
                    }
                }
            }
        }
    }
}
